/* inw.t   INVENTORY MASTER WRITE TRIGGER                             */
/*Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                 */
/*All rights reserved worldwide.  This is an unpublished work.        */
/*V8:ConvertMode=NoConvert*/
/*********************************************************************/
/*  Program :inw.t                                                   */
/*  Author  :Ben Holmes                                              */
/*  Date    :03/19/95                                                */
/*  !Description : in_mstr WRITE trigger program                     */
/*          : In order to enhance this trigger to support additional */
/*          : interfaces, add a DO-END block similar to the one      */
/*          : used for the Warehousing Interface to (1) check for the*/
/*          : need to continue processing; (2) move the relevant     */
/*          : fields to an appropriate work area; and (3) call       */
/*          : one or more subprograms to continue processing.        */
/*          : This .t program should remain short, relying on        */
/*          : subprograms to perform most of the work.               */
/*********************************************************************/
/*                             MODIFY LOG                            */
/*********************************************************************/
/*Revision 8.5          Last Modified:  03/19/95 BY: BHolmes *J0FY*  */
/*Revision 8.5          Last Modified:  07/27/96 BY: fwy     *J12B*  */
/*Revision 8.6          Last Modified:  11/20/96 BY: cjv     *K01B*  */
/*Revision 8.6          Last Modified:  01/07/97 BY: jpm     *J1DM*  */
/*Revision 9.1          Last Modified:  08/13/00 BY: *N0KR* myb       */
/*Revision 9.1          Last Modified:  11/14/00 BY: *N0TS* Robert Jensen */
/*Revision 9.0          Last Modified:  05/27/02 BY: *M1Z1* Deirdre O'Brien */
/*                                                                   */
/*********************************************************************/

TRIGGER PROCEDURE FOR WRITE OF IN_MSTR OLD BUFFER OLD_IN_MSTR.

/*J12B  if not can-find(first whl_mstr where whl_mstr.whl_act no-lock) */
/*J12B  then leave. */

        {mfdeclre.i }
        define new shared work-table wf_old_in_mstr like in_mstr.
        define new shared variable w-recid as recid.
        define variable w-file as character format "x(24)".


        /* Warehousing Interface processing */

        WI:
        do:

        /* If there is no active external warehouse, then do not process */
/*K01B     If the item export flag is not set, then do not process */
/*J12B*/    if not can-find(first whl_mstr no-lock
/*K01B  /*J12B*/        where whl_mstr.whl_act) */
/*K01B*/          where whl_mstr.whl_act
/*K01B*/          and whl_mstr.whl_pt_exp)
/*J12B*/    then leave WI.

        /* If no pertinent fields have been changed, then do not process */
/*J12B*/    if   (old_in_mstr.in_part         = in_mstr.in_part
/*J12B*/      and old_in_mstr.in_abc          = in_mstr.in_abc
/*J12B*/      and old_in_mstr.in_cyc_int      = in_mstr.in_cyc_int
/*J12B*/      and old_in_mstr.in_rctpo_status = in_mstr.in_rctpo_status
/*J12B*/      and old_in_mstr.in_user1        = in_mstr.in_user1
/*J12B*/      and old_in_mstr.in_user2        = in_mstr.in_user2)
/*J12B*/    then leave WI.

        /* Move old in_mstr values to work table for subsequent processing */
            assign w-recid = recid(in_mstr).
            create wf_old_in_mstr.
            if recid(wf_old_in_mstr)= -1 then .
            assign
                wf_old_in_mstr.in_part         = old_in_mstr.in_part
                wf_old_in_mstr.in_abc          = old_in_mstr.in_abc
                wf_old_in_mstr.in_cyc_int      = old_in_mstr.in_cyc_int
                wf_old_in_mstr.in_rctpo_status = old_in_mstr.in_rctpo_status
                wf_old_in_mstr.in_user1        = old_in_mstr.in_user1
                wf_old_in_mstr.in_user2        = old_in_mstr.in_user2
            .

        /* Call subprogram to create export transactions for warehouses */
            w-file = "wiinw.p".
/*J1DM*/ /* {gprun.i ""wiinw.p""} */
/*J1DM*/    {gprunmo.i &module="WI"
                       &program="wiinw.p"}

/*J12B*/end. /* WI */
/*N0TS*//* Logistics Interface processing */
/*N0TS*/LG:
/*N0TS*/do:
/*N0TS*//* If there is no logistics application ID, then do not process */
/*N0TS*/      if not can-find(first lgs_mstr no-lock
/*N0TS*/        where lgs_app_id <> "")
/*N0TS*/           then leave LG.
/*N0TS*/   for first soc_ctrl fields(soc_on_ord soc_req) no-lock:
/*N0TS*/   end.
         /*M1Z1*/ /* Create wf_old_in_mstr record if one doesn't exist*/
/*M1Z1*/   if not available wf_old_in_mstr then
/*M1Z1*/   do:
/*M1Z1*/      assign w-recid = recid(in_mstr).
/*M1Z1*/      create wf_old_in_mstr.
/*M1Z1*/      if recid(wf_old_in_mstr)= -1 then .
/*M1Z1*/      assign
/*M1Z1*/         wf_old_in_mstr.in_part         = old_in_mstr.in_part
/*M1Z1*/         wf_old_in_mstr.in_abc          = old_in_mstr.in_abc
/*M1Z1*/         wf_old_in_mstr.in_cyc_int      = old_in_mstr.in_cyc_int
/*M1Z1*/         wf_old_in_mstr.in_rctpo_status = old_in_mstr.in_rctpo_status
/*M1Z1*/         wf_old_in_mstr.in_user1        = old_in_mstr.in_user1
/*M1Z1*/         wf_old_in_mstr.in_user2        = old_in_mstr.in_user2.

/*M1Z1*/   end.
/*M1Z1*/   assign
/*M1Z1*/      wf_old_in_mstr.in_qty_req = old_in_mstr.in_qty_req
/*M1Z1*/      wf_old_in_mstr.in_qty_ord = old_in_mstr.in_qty_ord.

/*N0TS*//* If no pertinent fields have been changed, then do not process */
/*N0TS*/   if (old_in_mstr.in_qty_avail <> in_mstr.in_qty_avail) or
/*N0TS*/      (old_in_mstr.in_qty_all <> in_mstr.in_qty_all) or
              ((soc_req) and (in_mstr.in_qty_req <> wf_old_in_mstr.in_qty_req)) or
              ((soc_on_ord) and (in_mstr.in_qty_ord <> wf_old_in_mstr.in_qty_ord))
/*N0TS*/   then do:
/*N0TS*//*    Move old in_mstr values to work table for subsequent processing */
/*N0TS*/      if not can-find(first wf_old_in_mstr) then do:
/*N0TS*/         create wf_old_in_mstr.
/*N0TS*/         if recid(wf_old_in_mstr)= -1 then .
/*N0TS*/      end.
/*N0TS*/      buffer-copy old_in_mstr to wf_old_in_mstr no-error.
/*N0TS*/      /* Call subprogram to publish changed status for Logistics */
/*N0TS*/      {gprunmo.i &module="LG"
/*N0TS*/      &program="lgldex.p"
/*N0TS*/      &param="""(input recid(in_mstr))"""}
/*N0TS*/   end.
/*N0TS*/end. /* LG */
/*N0TS* *End of Added Section */

/* fdn 2004/10/28 Modify Record processing */
HK:
do:
    if can-find(first dt_mstr where dt_table = "in_mstr" and dt_type = "SYNC") then
        run CreateSyncFlag(input "MOD", input recid(in_mstr), input "in_mstr").

    if not can-find ( first dt_mstr where dt_table = "in_mstr" and dt_type = "MOD" ) then leave HK.
    
    if not can-find ( first wf_old_in_mstr ) then do:
        create wf_old_in_mstr.
        if recid(wf_old_in_mstr)= -1 then .
    end.
    
    buffer-copy old_in_mstr to wf_old_in_mstr no-error.

    for each dt_mstr no-lock where dt_table = "in_mstr" and dt_type = "MOD" :
    
        case dt_field :

            when "in_part" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_part, input in_mstr.in_part,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_site" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_site, input in_mstr.in_site,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_qty_oh" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_qty_oh), input string(in_mstr.in_qty_oh),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_qty_req" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_qty_req), input string(in_mstr.in_qty_req),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_qty_all" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_qty_all), input string(in_mstr.in_qty_all),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_qty_ord" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_qty_ord), input string(in_mstr.in_qty_ord),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_qty_chg" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_qty_chg), input string(in_mstr.in_qty_chg),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_qty_avail" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_qty_avail), input string(in_mstr.in_qty_avail),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_sls_chg" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_sls_chg), input string(in_mstr.in_sls_chg),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_iss_chg" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_iss_chg), input string(in_mstr.in_iss_chg),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_iss_date" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_iss_date), input string(in_mstr.in_iss_date),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_rec_date" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_rec_date), input string(in_mstr.in_rec_date),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_cnt_date" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_cnt_date), input string(in_mstr.in_cnt_date),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_avg_iss" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_avg_iss), input string(in_mstr.in_avg_iss),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_avg_sls" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_avg_sls), input string(in_mstr.in_avg_sls),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_avg_date" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_avg_date), input string(in_mstr.in_avg_date),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_user1" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_user1, input in_mstr.in_user1,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_user2" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_user2, input in_mstr.in_user2,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_rop" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_rop), input string(in_mstr.in_rop),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_sfty_stk" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_sfty_stk), input string(in_mstr.in_sfty_stk),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_qty_nonet" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_qty_nonet), input string(in_mstr.in_qty_nonet),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_mrp" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_mrp), input string(in_mstr.in_mrp),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_gl_set" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_gl_set, input in_mstr.in_gl_set,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_cur_set" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_cur_set, input in_mstr.in_cur_set,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_abc" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_abc, input in_mstr.in_abc,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_avg_int" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_avg_int), input string(in_mstr.in_avg_int),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_cyc_int" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_cyc_int), input string(in_mstr.in_cyc_int),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_level" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_level), input string(in_mstr.in_level),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_loc" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_loc, input in_mstr.in_loc,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_loc_type" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_loc_type, input in_mstr.in_loc_type,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_proj_use" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_proj_use), input string(in_mstr.in_proj_use),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_grade" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_grade, input in_mstr.in_grade,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_assay" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_assay), input string(in_mstr.in_assay),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_rollup" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_rollup), input string(in_mstr.in_rollup),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_rollup_id" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_rollup_id, input in_mstr.in_rollup_id,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_rctpo_status" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_rctpo_status, input in_mstr.in_rctpo_status,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_rctwo_status" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_rctwo_status, input in_mstr.in_rctwo_status,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_rctpo_active" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_rctpo_active), input string(in_mstr.in_rctpo_active),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_rctwo_active" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_rctwo_active), input string(in_mstr.in_rctwo_active),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in__qadc01" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in__qadc01, input in_mstr.in__qadc01,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_wh" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_wh), input string(in_mstr.in_wh),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_gl_cost_site" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_in_mstr.in_gl_cost_site, input in_mstr.in_gl_cost_site,
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_cust_consign_qty" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_cust_consign_qty), input string(in_mstr.in_cust_consign_qty),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").

            when "in_supp_consign_qty" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_in_mstr.in_supp_consign_qty), input string(in_mstr.in_supp_consign_qty),
                    input recid(in_mstr), input in_mstr.in_part, input in_mstr.in_site, input "", input "",
                    input "", input "", input "", input "").
        end.
    end.
end.

{hkdttrans.i}
